package com.mycc.dao;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mycc.damin.TbTicketOrders;
import com.mycc.damin.TbTours;
import com.mycc.damin.TicketOrderDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ticketOrdersDao extends BaseMapper<TbTicketOrders> {

    //查询所有订单
    @Select("SELECT " +
            "t.name AS touristName, " +
            "t.id_number AS idNumber, " +
            "t.contact_info AS contactInfo, " +
            "g.name AS guidesName, " +
            "g.other_details AS otherDetails, " +
            "tr.name AS toursName, " +
            "tr.location AS toursLocation, " +
            "`to`.order_status AS orderStatus, " + // 注意这里使用了反引号
            "`to`.order_date AS orderDate " + // 注意这里使用了反引号
            "FROM tb_ticket_orders `to` " + // 注意这里使用了反引号
            "JOIN tb_tourists t ON `to`.tourist_id = t.id " +
            "JOIN tb_tours tr ON `to`.tour_id = tr.id " +
            "LEFT JOIN tb_guides g ON tr.guide_id = g.id")
    @Results({
            @Result(column = "touristName", property = "touristName"),
            @Result(column = "idNumber", property = "idNumber"),
            @Result(column = "contactInfo", property = "contactInfo"),
            @Result(column = "guidesName", property = "guidesName"),
            @Result(column = "otherDetails", property = "otherDetails"),
            @Result(column = "toursName", property = "toursName"),
            @Result(column = "toursLocation", property = "toursLocation"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "orderDate", property = "orderDate")
    })
    IPage<TicketOrderDto> selectTicketOrdersWithRelations(IPage<TicketOrderDto> page);

    //查询单个订单
    @Select("SELECT " +
            "t.name AS touristName, " +
            "t.id_number AS idNumber, " +
            "t.contact_info AS contactInfo, " +
            "g.name AS guidesName, " +
            "g.other_details AS otherDetails, " +
            "tr.name AS toursName, " +
            "tr.location AS toursLocation, " +
            "`to`.order_status AS orderStatus, " + // 注意这里使用了反引号
            "`to`.order_date AS orderDate " + // 注意这里使用了反引号，并且与上一个字段之间有空格
            "FROM tb_ticket_orders `to` " + // 注意这里to后面有空格，并且使用了反引号
            "JOIN tb_tourists t ON `to`.tourist_id = t.id " +
            "JOIN tb_tours tr ON `to`.tour_id = tr.id " +
            "LEFT JOIN tb_guides g ON tr.guide_id = g.id " +
            "WHERE `to`.id = #{id}")
    @Results({
            @Result(column = "touristName", property = "touristName"),
            @Result(column = "idNumber", property = "idNumber"),
            @Result(column = "contactInfo", property = "contactInfo"),
            @Result(column = "guidesName", property = "guidesName"),
            @Result(column = "otherDetails", property = "otherDetails"),
            @Result(column = "toursName", property = "toursName"),
            @Result(column = "toursLocation", property = "toursLocation"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "orderDate", property = "orderDate")
    })
    TicketOrderDto selectTicketOrderById(int id);


    //通过id修改订单
//    @Update("UPDATE tb_ticket_orders SET order_status = #{orderStatus}, " +
//            "tourist_name = #{touristName}, id_number = #{idNumber}, " +
//            "contact_info = #{contactInfo} WHERE id = #{id}")
//    @Results({
//            @Result(column = "orderStatus", property = "orderStatus"),
//            @Result(column = "contactInfo", property = "contactInfo"),
//            @Result(column = "toursName", property = "toursName")
//    })
//    int updateTicketOrder(@Param("id") Long id, @Param("ticketOrderDto") TicketOrderDto ticketOrderDto);
}


